BKT Suomi
ptt_data_robo_l("StatFin/kan/ntp/statfin_ntp_pxt_132h.px") |>
filter(
taloustoimi == "B1GMH Bruttokansantuote markkinahintaan",
tiedot == "Kausitasoitetun ja työpäiväkorjatun sarjan volyymin muutos vuodentakaisesta, %",
time >= "2014-01-01"
) |>
mutate(tiedot = "BKT") |>
ptt_plot(
grouping = tiedot,
title = "BKT Suomi",
subtitle = "Vuosimuutos",
caption = "Lähde: Tilastokeskus ja PTT",
rangeslider = FALSE,
zeroline = T,
font_size = 14,
height = 500,
hovertext = list(rounding = 1, unit = "%", extra = "")
) |>
ptt_plot_add_prediction(ennuste_data) |>
ptt_plot_create_widget()
#> i Connecting to robonomistServer at ptt.robonomist.com
#> v Connecting to robonomistServer at ptt.robonomist.com [290ms]
#>
#> i Connected successfully to robonomistServer 2.5.12
#> v Connected successfully to robonomistServer 2.5.12 [67ms]
#>
#> \ Requesting get
#> v Requesting get [414ms]
#>
#> Using "bkt_suomi" for htmlwidget filename..
#>
#> <iframe src="https://storage.googleapis.com/pttry/ennustekuvat/ennustekuvat_test_artefacts/bkt_suomi.html" width="100%" scrolling="no" marginheight="0" frameborder="0" height="480px"></iframe>
Venäjän loppukysynnän osuus arvonlisästä
pdat_tiva_va <- robonomistClient::data_get("oecd/TIVA_2021_C1", tidy_time = TRUE) |>
filter(
Indicator %in% c("Value added", "Domestic value added embodied in foreign final demand"),
`Country / Region` %in% c("Finland", "Euro area (19 countries)", "China (People's Republic of)", "United States"),
# `Partner country / region` %in% c("Russian Federation", "World"),
Industry == "TOTAL"
) |>
collect() |>
mutate(value = as.numeric(value)) |>
statfitools::clean_names() |>
mutate(across(where(is.character), as_factor))
#> \ Requesting get
#> v Requesting get [103ms]
#>
#> \ Requesting get
#> v Requesting get [129ms]
#>
pdat_tiva_va |>
filter_recode(
country_region = c(
"Suomi" = "Finland",
"Euroalue" = "Euro area (19 countries)",
"Kiina" = "China (People's Republic of)",
"USA" = "United States"
)
# ,
# partner_country_region = c("Russian Federation")
) |>
group_by(time, country_region) |>
summarise(value = 100*value[indicator == "Domestic value added embodied in foreign final demand" &
partner_country_region == "Russian Federation"] /
value[indicator == "Value added"]) |>
ungroup() |>
aplot_lines(colour = country_region,
title = "Venäjän loppukysynnän osuus BKT:sta",
subtitle ="%",
source = "OECD") |>
ptt_plot_create_widget()
#> `summarise()` has grouped output by 'time'. You can override using the
#> `.groups` argument.
#> No frequency attribute detected for hovertext time format, resorting to default %Y/%m/%d.
#> Using "venajan_loppukysynnan_osuus_bktsta" for htmlwidget filename..
#>
#> <iframe src="https://storage.googleapis.com/pttry/ennustekuvat/ennustekuvat_test_artefacts/venajan_loppukysynnan_osuus_bktsta.html" width="100%" scrolling="no" marginheight="0" frameborder="0" height="480px"></iframe>
BKT USA, euroalue, Suomi
# luodaan bkt:t usa, suomi ja euroalue. indeksoidaan, perusvuodeksi 2020.
usa_bkt <-
ptt_data_robo("fred/GDPC1") |>
filter(time >= "2014-01-01") |>
select(tiedot = series_id, time, value) |>
mutate(tiedot = "USA")
#> \ Requesting get
#> v Requesting get [798ms]
#>
suomi_bkt <-
ptt_data_robo_l("StatFin/kan/ntp/statfin_ntp_pxt_132h.px") |>
filter(
taloustoimi == "B1GMH Bruttokansantuote markkinahintaan",
tiedot == "Kausitasoitettu ja työpäiväkorjattu sarja, viitevuosi 2015, miljoonaa euroa",
time >= "2014-01-01"
) |>
select(tiedot, time, value) |>
mutate(tiedot = "Suomi")
#> \ Requesting get
#> v Requesting get [293ms]
#>
euroalue_bkt <-
ptt_data_robo_l("eurostat/namq_10_gdp") |>
filter(
geo == "Euro area - 19 countries (from 2015)",
na_item == "Gross domestic product at market prices",
s_adj == "Seasonally and calendar adjusted data",
unit == "Chain linked volumes, index 2015=100",
time >= "2014-01-01"
) |>
select(tiedot = na_item, time, value) |>
mutate(tiedot = "Euroalue")
#> \ Requesting get
#> | Requesting get
#> / Requesting get
#> - Requesting get
#> v Requesting get [18.7s]
#>
yhdistetty_bkt_data <-
bind_rows(usa_bkt, suomi_bkt, euroalue_bkt) |>
group_by(across(!c(time, value))) |>
mutate(value = rebase(value, time, 2019)) |>
ungroup()
# apufunktio indeksoinnin laskemiseen
avg_value_2021 <- function(d, sarja) {
d |>
filter(tiedot == sarja) |>
filter(year(time) == 2021) |>
pull(value) |> mean()
}
# Muokataan ennustedata.
bkt_vertailu_ennusteet <-
ennuste_data |>
filter(sarja_nmi %in% c("BKT")) |>
mutate(across(matches("[0-9]{4}"), ~ as.double(.x))) |>
pivot_longer(cols = matches("[0-9]{4}"), names_to = "year") |>
select(year, sarja_nmi, value) |>
group_by(sarja_nmi) |>
slice_tail(n = 2)
#muokataan suomen BKT ennustedata indeksoituun muotoon
ennuste_indeksoitu_2022 <- bkt_vertailu_ennusteet |>
filter(year == "2022") |>
mutate(value = avg_value_2021(yhdistetty_bkt_data, "Suomi") * (1 + value/100))
ennuste_indeksoitu_2023 <- bkt_vertailu_ennusteet |>
filter(year == "2023") |>
mutate(value = (ennuste_indeksoitu_2022$value * (1 + value/100)))
ennusteet_suomi_bkt <- bind_rows(ennuste_indeksoitu_2022, ennuste_indeksoitu_2023) |>
mutate(sarja_nmi = "Suomi")
# luodaan kuvaaja käyttäen yhdistettyä bkt dataa sekä muodostettua ennustedataa
yhdistetty_bkt_data|>
ptt_plot(
grouping = tiedot,
title = "Bruttokansantuote",
subtitle = "Indeksi 2019 = 100",
caption = "Lähde: Tilastokeskus, BEA, Eurostat ja PTT",
rangeslider = FALSE,
## rangeslider = "2015-01-01",
zeroline = F,
hovertext = list(rounding = 1, unit = "(indeksi 2020=100)", extra = "")
# ,
# axis_limits = list(y = c(89, 113))
) |>
ptt_plot_add_prediction(ennusteet_suomi_bkt, custom_pred_data = TRUE) |>
ptt_plot_create_widget()
#> No frequency attribute detected for hovertext time format, resorting to default %Y/%m/%d.
#> Using "bruttokansantuote" for htmlwidget filename..
#>
#> <iframe src="https://storage.googleapis.com/pttry/ennustekuvat/ennustekuvat_test_artefacts/bruttokansantuote.html" width="100%" scrolling="no" marginheight="0" frameborder="0" height="480px"></iframe>
Vienti ja tuonti
ptt_data_robo_l("StatFin/kan/ntp/statfin_ntp_pxt_132h.px") |>
filter(
taloustoimi %in% c("P7R Tavaroiden ja palvelujen tuonti, tulona",
"P6K Tavaroiden ja palvelujen vienti, menona"),
tiedot == "Kausitasoitetun ja työpäiväkorjatun sarjan volyymin muutos vuodentakaisesta, %",
time >= "2014-01-01"
) |>
mutate(
tiedot = recode(taloustoimi,
"P7R Tavaroiden ja palvelujen tuonti, tulona" = "Tuonti",
"P6K Tavaroiden ja palvelujen vienti, menona" = "Vienti"
)
) |>
ptt_plot(
grouping = tiedot,
title = "Vienti ja tuonti",
subtitle = "%, volyymin vuosimuutos",
caption = "Lähde: Tilastokeskus ja PTT",
rangeslider = FALSE,
zeroline = T,
hovertext = list(rounding = 1, unit = "", extra = "")
) |>
ptt_plot_add_prediction(ennuste_data) |>
ptt_plot_create_widget()
#> \ Requesting get
#> v Requesting get [2s]
#>
#> Using "vienti_ja_tuonti" for htmlwidget filename..
#>
#> <iframe src="https://storage.googleapis.com/pttry/ennustekuvat/ennustekuvat_test_artefacts/vienti_ja_tuonti.html" width="100%" scrolling="no" marginheight="0" frameborder="0" height="480px"></iframe>
ptt_plot_upload_widgets()